package com.itheima.stock.controller;

import com.itheima.stock.pojo.domain.*;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Api("/api/quot")
@RestController
@RequestMapping("/api/quot")
public class StockController {
    @Autowired
    private StockService stockService;

    @ApiOperation(value = "获取国内最新大盘数据", notes = "获取国内最新大盘数据", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarkDomain>> getInnerMarketInfo(){
      return   stockService.getInnerMarketInfo();

    }
    @ApiOperation(value = "国内板块指数功能实现", notes = "国内板块指数功能实现", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getSectorAll(){
        return stockService.getSectorAll();
    }
    //主要区股票展示分页查询
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "")
    })
    @ApiOperation(value = "主要区股票展示分页查询", notes = "主要区股票展示分页查询", httpMethod = "GET")
    @GetMapping("/stock/all")
        public R<PageResult<StockUpdownDomain>> getStockInfoByPage(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                                                                   @RequestParam(value = "pageSize",required = false,defaultValue = "20") Integer pageSize){

            return stockService.getStockInfoByPage(page,pageSize);
        }

//涨幅榜数据采集
        @ApiOperation(value = "涨幅榜数据采集", notes = "涨幅榜数据采集", httpMethod = "GET")
        @GetMapping("/stock/increase")
    private R<List<StockUpdownDomain>> getUpDownStockInfo(){
        return stockService.getUpDownStockInfo();
        }
//统计最新交易日股票涨停数量
        @ApiOperation(value = "统计最新交易日股票涨停数量", notes = "统计最新交易日股票涨停数量", httpMethod = "GET")
        @GetMapping("/stock/updown/count")
    public R<Map<String,List>> getStockUpDown(){

        return stockService.getStockUpDown();
        }


    /**
     *  股票展示分页--导出--数据
     * @param page 当前页
     * @param pageSize 每页大小
     * @param resp 响应
     */

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "每页大小")
    })
    @ApiOperation(value = "股票展示分页--导出--数据", notes = "股票展示分页--导出--数据", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void exportStockUpDownInfo(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                                   @RequestParam(value = "pageSize",required = false,defaultValue = "20") Integer pageSize, HttpServletResponse resp){
         stockService.exportStockUpDownInfo(page,pageSize,resp);
    }


    /**
     * 统计T日和T-1每分钟交易额
     * @return
     */
    @ApiOperation(value = "统计T日和T-1每分钟交易额", notes = "统计T日和T-1每分钟交易额", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String,List>> getComparedStockTradeAmt(){

        return  stockService.getComparedStockTradeAmt();
    }

    /**
     * 统计最新时间股票各个涨幅区间的个数
     * @return
     */
    @ApiOperation(value = "统计最新时间股票各个涨幅区间的个数", notes = "统计最新时间股票各个涨幅区间的个数", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map> getIncreaseRangeInfo(){

        return stockService.getIncreaseRangeInfo();
    }

    /**
     * T日分时数据线
     * @param stockCode
     * @return
     */

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "stockCode", value = "", required = true)
    })
    @ApiOperation(value = "T日分时数据线", notes = "T日分时数据线", httpMethod = "GET")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getScreenTimeSharing(@RequestParam(value = "code",required = true) String stockCode){
        return stockService.getScreenTimeSharing(stockCode);
    }

    /**
     * 统计股票日k线
     * @param stockCode
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "stockCode", value = "", required = true)
    })
    @ApiOperation(value = "统计股票日k线", notes = "统计股票日k线", httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getScreenDKline(@RequestParam("code") String stockCode){
        return stockService.getScreenDKline(stockCode);
    }


}
